package 剑指offer.树的子结构_17;

public class Main {
    public boolean HasSubtree(TreeNode root1,TreeNode root2) {
        boolean res = false;
        if(root1 != null && root2 != null){
            if(root1.val == root2.val){
            	res = getRes(root1, root2);
            }
            if(!res){
            	res = HasSubtree(root1.left, root2);
            }
            if(!res){
            	res = HasSubtree(root1.right, root2);
            }
        }
    	return res;
    }

	private boolean getRes(TreeNode root1, TreeNode root2) {
		if(root2 == null) return true;
		if(root1 == null) return false;
        if(root1.val != root2.val) return false;
		return getRes(root1.left, root2.left)&&getRes(root1.right, root2.right);
	}
}
